# vim: foldmethod=marker
# Oh-My-Zsh {{{1

export ZSH="${HOME}/.oh-my-zsh"

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

plugins=(
    aws
    colored-man-pages
    docker
    F-Sy-H
    git
    golang
    helm
    httpie
    kubectl
    npm
    terraform
    vi-mode
    you-should-use
    z
    zsh-autosuggestions
    zsh-nvm
    fzf-tab # fzf-tab should be the last plugin to bind "^I"
)

# Settings that must be applied before loading Oh-My-Zsh {{{2

# Set the theme
ZSH_THEME="powerlevel10k/powerlevel10k"

# Use case-sensitive completion
CASE_SENSITIVE="true"

# Fix slow paste
DISABLE_MAGIC_FUNCTIONS=true

# Workaround for https://github.com/zsh-users/zsh-completions/issues/603
if [[ -d "${ZSH_CUSTOM}/plugins/zsh-completions/src" ]]; then
  fpath+="${ZSH_CUSTOM}/plugins/zsh-completions/src"
fi

if [[ -n "${HOMEBREW_PREFIX+1}" ]]; then
    fpath+="${HOMEBREW_PREFIX}/share/zsh/site-functions"
fi

# }}}

# Load oh-my-zsh
source "${ZSH}/oh-my-zsh.sh"

# ZSH {{{1

# Apply sensisble zsh settings
setopt ALWAYS_TO_END        # full completions move cursor to the end
setopt AUTO_CD              # `dirname` is equivalent to `cd dirname`
setopt AUTO_PARAM_SLASH     # if completed parameter is a directory, add a trailing slash
setopt AUTO_PUSHD           # `cd` pushes directories to the directory stack
setopt CHASE_LINKS          # Resolve symbolic links to their true values when changing directory
setopt COMPLETE_IN_WORD     # complete from the cursor rather than from the end of the word
setopt C_BASES              # print hex/oct numbers as 0xFF/077 instead of 16#FF/8#77
setopt EXTENDED_GLOB        # more powerful globbing
setopt INTERACTIVE_COMMENTS # allow comments in command line
setopt MULTIOS              # allow multiple redirections for the same fd
setopt NO_BG_NICE           # don't nice background jobs
setopt NO_FLOW_CONTROL      # disable start/stop characters in shell editor
setopt PATH_DIRS            # perform path search even on command names with slashes
setopt correct              # Correct typos
unsetopt FLOW_CONTROL       # Disable start/stop characters output (usually assigned to ^S/^Q) in the shell's editor.

setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS

# Bind C+Space to accept the current suggestion
bindkey '^ ' autosuggest-accept

# Set the default umask
umask 022

# Source files {{{2

# Apply FZF configuration
eval "$(fzf --zsh)"

# Load any extra settings
if [[ -f "${HOME}/dotfiles/zsh/extras" ]]; then
    source "${HOME}/dotfiles/zsh/extras"
fi

# Completion {{{2

# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'

# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false

# Only display targets tag for make command completion
zstyle ':completion:*:*:make::' tag-order 'targets variables'

# give a preview of commandline arguments when completing `kill`
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"

# fzf-tab settings
# switch group using `,` and `.`
zstyle ':fzf-tab:*' switch-group ',' '.'

# remove prefix
zstyle ':fzf-tab:*' prefix ''

# Whether to automatically insert a space after the result.
zstyle ':fzf-tab:*' insert-space false

# Other {{{2

# disable highlighting of pasted text
zle_highlight=('paste:none')

# Reload the completions (uncomment if zsh-completions don't work)
# autoload -U compinit && compinit
